package exp3;

public class Complex {
    protected double RealPart;
    protected double ImagePart;

    public Complex(){
        RealPart = 0;
        ImagePart = 0;
    }

    public Complex(double R, double I){
        RealPart = R;
        ImagePart = I;
    }

    public double getRealPart() {
        return RealPart;
    }

    public void setRealPart(double realPart) {
        RealPart = realPart;
    }

    public double getImagePart() {
        return ImagePart;
    }

    public void setImagePart(double imagePart) {
        ImagePart = imagePart;
    }

    public boolean equals(Complex com){
        if (RealPart == com.getRealPart() && ImagePart == com.getImagePart())
            return true;
        else
            return false;
    }

    public Complex ComplexAdd(Complex complex){
        RealPart += complex.getRealPart();
        ImagePart += complex.getImagePart();
        return new Complex(RealPart, ImagePart);
    }

    public Complex ComplexSub(Complex complex){
        RealPart = RealPart - complex.getRealPart();
        ImagePart = ImagePart - complex.getImagePart();
        return new Complex(RealPart, ImagePart);
    }

    public Complex ComplexMulti(Complex complex){
        double a, b;
        a = RealPart * complex.getRealPart() - ImagePart * complex.getImagePart();
        b = ImagePart * complex.getRealPart() + RealPart * complex.getImagePart();
        return new Complex(a, b);
    }

    public Complex ComplexDiv(Complex complex){
        double domen, numerR, numerI;
        numerR = RealPart * complex.getRealPart() + ImagePart * complex.getImagePart();
        numerI = ImagePart * complex.getRealPart() - RealPart * complex.getImagePart();
        domen = Math.pow(complex.getRealPart(), 2) + Math.pow(complex.getImagePart(), 2);
        RealPart = numerR / domen;
        ImagePart = numerI / domen;
        return new Complex(RealPart, ImagePart);
    }

    @Override
    public String toString() {
        return RealPart + "+(" + ImagePart + ")i";
    }


}

